using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the Site class.
	/// </summary>
	[Serializable]
	public partial class SiteCollection : ActiveList<Site,SiteCollection> 
	{	   
		public SiteCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Site table.
	/// </summary>
	[Serializable]
	public partial class Site : ActiveRecord<Site>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Site()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Site(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Site(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Site(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Site", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarSiteId = new TableSchema.TableColumn(schema);
				colvarSiteId.ColumnName = "SiteId";
				colvarSiteId.DataType = DbType.Guid;
				colvarSiteId.MaxLength = 0;
				colvarSiteId.AutoIncrement = false;
				colvarSiteId.IsNullable = false;
				colvarSiteId.IsPrimaryKey = true;
				colvarSiteId.IsForeignKey = false;
				colvarSiteId.IsReadOnly = false;
				colvarSiteId.DefaultSetting = @"";
				colvarSiteId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSiteId);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 50;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = false;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				colvarName.DefaultSetting = @"";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarApplicationId = new TableSchema.TableColumn(schema);
				colvarApplicationId.ColumnName = "ApplicationId";
				colvarApplicationId.DataType = DbType.Guid;
				colvarApplicationId.MaxLength = 0;
				colvarApplicationId.AutoIncrement = false;
				colvarApplicationId.IsNullable = false;
				colvarApplicationId.IsPrimaryKey = false;
				colvarApplicationId.IsForeignKey = false;
				colvarApplicationId.IsReadOnly = false;
				colvarApplicationId.DefaultSetting = @"";
				colvarApplicationId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplicationId);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Site",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("SiteId")]
		public Guid SiteId 
		{
			get { return GetColumnValue<Guid>(Columns.SiteId); }

			set { SetColumnValue(Columns.SiteId, value); }

		}

		  
		[XmlAttribute("Name")]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }

			set { SetColumnValue(Columns.Name, value); }

		}

		  
		[XmlAttribute("ApplicationId")]
		public Guid ApplicationId 
		{
			get { return GetColumnValue<Guid>(Columns.ApplicationId); }

			set { SetColumnValue(Columns.ApplicationId, value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		private Medianamik.SubsonicDALProvider.DAL.SiteModuleCollection colSiteModuleRecords;
		public Medianamik.SubsonicDALProvider.DAL.SiteModuleCollection SiteModuleRecords()
		{
			if(colSiteModuleRecords == null)
				colSiteModuleRecords = new Medianamik.SubsonicDALProvider.DAL.SiteModuleCollection().Where(SiteModule.Columns.SiteId, SiteId).Load();
			return colSiteModuleRecords;
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varSiteId,string varName,Guid varApplicationId)
		{
			Site item = new Site();
			
			item.SiteId = varSiteId;
			
			item.Name = varName;
			
			item.ApplicationId = varApplicationId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varSiteId,string varName,Guid varApplicationId)
		{
			Site item = new Site();
			
				item.SiteId = varSiteId;
			
				item.Name = varName;
			
				item.ApplicationId = varApplicationId;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn SiteIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ApplicationIdColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string SiteId = @"SiteId";
			 public static string Name = @"Name";
			 public static string ApplicationId = @"ApplicationId";
						
		}

		#endregion
		
		
		
	}

}

